import {https} from "@/utils/request";
import {
    ContainerListProp,
    ContainerListQueryProp,
    ContainerOperateProp,
    ImageListProp,
    ImageListQueryProp, ImagePullResultProp, ImageSearchProp, ImageSearchQueryProp, ImageTagQueryProp, ImageTagTableProp
} from "@/pages/docker/modules";
import {PageData} from "@/utils/http";
import {is} from "@/utils/other";

// containerList 容器列表查询
export const containerList = (data: ContainerListQueryProp): Promise<PageData<ContainerListProp>> => {
    return https.request({
        url: '/docker/container/page',
        method: 'post',
        data: data
    })
}

// containerOperate 容器相关操作
export const containerOperate = (data: ContainerOperateProp): Promise<string> => {
    return https.request({
        url: '/docker/container/operate',
        method: 'post',
        data: data
    })
}

// containerList 镜像列表查询
export const imagesList = (data: ImageListQueryProp): Promise<PageData<ImageListProp>> => {
    return https.request({
        url: '/docker/images/page',
        method: 'post',
        data: data
    })
}

// imagesSearch 镜像搜索
export const imagesSearch = (data: ImageSearchQueryProp): Promise<ImageSearchProp[]> => {
    return https.request({
        url: '/docker/images/search',
        method: 'post',
        data: data
    })
}

// imagesPull 镜像拉取
export const imagesPull = (name: string): Promise<ImagePullResultProp> => {
    return https.request({
        url: '/docker/images/pull',
        method: 'get',
        params: {name: name}
    })
}

// imagesSearch 镜像Tag获取
export const imagesTags = (data: ImageTagQueryProp): Promise<PageData<ImageTagTableProp>> => {
    return https.request({
        url: '/docker/images/tags',
        method: 'post',
        data: data
    })
}

// imagesPullResult 镜像拉取结果查询
export const imagesPullResult = (id: number): Promise<ImagePullResultProp> => {
    return https.request({
        url: '/docker/images/pullResult',
        method: 'get',
        params: {id: id}
    })
}

// imagesSearch 镜像设置Tag获取
export const imagesSetTags = (data: {imageId: string, tag: string}): Promise<string> => {
    return https.request({
        url: '/docker/images/tag',
        method: 'post',
        data: data
    })
}

// imagesRemove 镜像移除
export const imagesRemove = (imageId: string, isForce: boolean): Promise<string> => {
    return https.request({
        url: '/docker/images/remove',
        method: 'get',
        params: {id: imageId, isForce: isForce}
    })
}

// imagesRemove 镜像移除
export const imagesInfo = (imageId: string): Promise<any> => {
    return https.request({
        url: '/docker/images/info',
        method: 'get',
        params: {imageId: imageId}
    })
}